#pragma once
#include "RPCData.h"
#include "SerializaReadWrite.h"
#include <boost/asio.hpp>
#include <boost/serialization/vector.hpp>
#include <functional>
#include <string>

using boost::asio::ip::tcp;

namespace UTILS {

using ReadFunc = std::function<void(std::string)>;
using WriteFunc = std::function<void(const boost::system::error_code &)>;

class Session : public std::enable_shared_from_this<Session> {
private:
  SerializaReadWritePtr m_ReadWriteMgr_;
  std::vector<RPCData> m_RPCData_;
  ReadFunc m_readFunc_;
  WriteFunc m_writeFunc_;

private:
  void handle_read();
  void handle_write(const boost::system::error_code &);
  boost::asio::awaitable<void> read();

public:
  Session(SerializaReadWritePtr);
  void stop();
  void start();
  void write(const uint32_t, std::string);
  void attachRead(const ReadFunc &);
  void attachWrite(const WriteFunc &);
};
} // namespace UTILS